package com.zxy.controller.v1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zxy.entity.v1.Person;
import com.zxy.service.v1.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: TODO
 * @Author: zhuxianyu
 * @Date: 2021/12/17 22:13
 * @Version: 1.0
 */
@Controller
@RequestMapping("/v1")
public class PersonController {

    @Autowired
    PersonService personService;

    @RequestMapping(value = "/select/person", method = RequestMethod.GET)
    @ResponseBody
    public JSONObject selectlist(@RequestParam("status") String status, @RequestParam("n") Integer n) {
        if (status.equals("ok")) {
            List<Person> personlist = personService.selectList(n);
            JSONArray jsonArray = new JSONArray();
            jsonArray.addAll(personlist);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personlist", jsonArray);
            return jsonObject;
        } else {
            return null;
        }
    }

}
